<?php
/**
 * @file bg-bb.php	Fixed!
 * @version 0.1
 * @desc 交易委托，买入、卖出
 * 
 * 上20%下10%，发布必须100的倍数，税收有小数时，四舍五入
 */
$action = $_POST['action'];
$user_id = $_POST['user_id'];
$flag = $_POST['flag'];
$knum = $_POST['knum'];
$kprice = $_POST['kprice'];

$msg = 0;
/**
 * 1. 流水操作成功
 * 
 * 444. 数据库连接失败
 * 
 * 410. action为空 或者 错误
 * 411. 用户为空
 * 412. 操作数knum为空
 * 413. 操作数kprice为空
 * 414. 操作数flag为空
 * 415. flag错误
 * 
 */
if (empty($action)){
	$msg = 410;
}elseif (empty($user_id)){
	$msg = 411;
}elseif (empty($knum)){
	$msg = 412;
}elseif (empty($kprice)){
	$msg = 413;
}elseif (empty($flag)){
	$msg = 414;
}

//登录验证
require_once 'setting.php';
if (validaStatus4AJAX() == 1){
	$msg = 403;
}

if ($msg == 0){
	/* 3,买入 ; 4,卖出; */ 
	if ( in_array($flag, array('3','4')) ){
		$sql = "CALL ".DB_NAME_KBAO.".sp_trust_t({$user_id}, {$knum}, {$kprice}, {$flag})";
		Appleseed::executeSQL($sql);
		$msg=1;
	}else{
		$msg = 415;
	}
}//END if
echo json_encode($msg);
?>